import 'package:flutter/material.dart';
import 'package:flutter_html/style.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:x3_base_package/x3_base_package.dart';

class BusinessCustomerDetailsServiceHtDetails extends StatefulWidget {

  static final String sName = 'BusinessCustomerDetailsServiceHtDetails';

  @override
  _BusinessCustomerDetailsServiceHtDetailsState createState() => _BusinessCustomerDetailsServiceHtDetailsState();

}

class _BusinessCustomerDetailsServiceHtDetailsState extends State<BusinessCustomerDetailsServiceHtDetails> {

  @override
  Widget build(BuildContext context) {
    dynamic arguments = BaseRouterUtil.getArguments(context);
    String topicId = BaseUtils.getKeyData(arguments, 'topicId').toString();
    return BaseScaffoldComponent(
      backGroundColor: Colors.white,
      title: '话题详情',
      child: BaseScreenRefreshComponent(
        request: BaseScreenRequestModel('/vip/topic/v1/query/detail/id/{topicId}', params: { 'topicId': topicId }, method: BaseHttpMethodEnum.GET ),
        controller: BaseFutureController(),
        builder: _buildHtWidget,
      ),
    );
  }

  Widget _buildHtWidget(BaseHttpResultModel result) {
    return ListView(
      padding: const EdgeInsets.all(12.0),
      children: [
        _buildServiceHtTitleWidget(result),
        _buildServiceHtUserInfoWidget(result),
        _buildServiceHtContentWidget(result),
      ],
    );
  }

  Widget _buildServiceHtTitleWidget(BaseHttpResultModel result) {
    String title = BaseUtils.getKeyData(result.data, 'topicTitle').toString();
    return Padding(
      padding: const EdgeInsets.only(bottom: 12.0),
      child: Text(
        title,
        style: Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 20.0, fontWeight: FontWeight.bold),
      ),
    );
  }

  Widget _buildServiceHtUserInfoWidget(BaseHttpResultModel result) {
    String createUsername = BaseUtils.getKeyData(result.data, 'createUsername').toString();
    String createDate = BaseUtils.getKeyData(result.data, 'createDate').toString();
    String createUserIcon = BaseUtils.getKeyData(result.data, 'createUserIcon').toString();
    String initCreateDate = BaseTransformUtil.stringToDateTimeStamp(createDate);
    return Row(
      children: [
        BaseImageComponent(imageUrl: createUserIcon, type: BaseImageTypeEnum.X3User, placeholderName: createUsername, width: 40.0, height: 40.0, circular: 40.0, size: BaseImageSizeEnum.original),
        SizedBox(width: 4.0),
        BaseComponentUtils.buildTextSpanWidget([createUsername, initCreateDate], styles: {0: Theme.of(context).textTheme.subtitle2, 1: Theme.of(context).textTheme.subtitle2,}),
      ],
    );
  }

  Widget _buildServiceHtContentWidget(BaseHttpResultModel result) {
    String content = BaseUtils.getKeyData(result.data, 'remark').toString();
    Style _style = Style(letterSpacing: 1, fontSize: FontSize.large);
    return Html(data: content, style: {"div": _style, "p": _style});
  }

}
